fix(mcp): keep search index type in vector hydration#983
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Closing in favor of #984, which contains the same patch with the required DCO sign-off trailer. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 16144196fc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| for si_key, similarity in similarity_by_si_key.items(): | ||
| row = search_index_rows.get(si_key) |
There was a problem hiding this comment.
Preserve row type during hybrid fusion
Now that vector hydration can append multiple SearchIndexRows with the same numeric id but different type, default hybrid searches still drop one of them because _search_hybrid stores FTS/vector rows in rows_by_id, fts_scores, and vec_scores keyed only by row.id (see src/basic_memory/repository/search_repository_base.py around lines 2207-2239). In semantic-enabled clients where hybrid is the default, a vector match for entity:4 and relation:4 will collapse to whichever row is assigned last, so the collision this patch fixes for vector-only remains user-visible in hybrid mode; carry the (type, id) key through the fusion maps as well.
Useful? React with 👍 / 👎.
Fixes #982.
Summary
(type, id)instead of bareid, so entity/relation/observation rows with the same search_index id no longer overwrite each other.WHERE id IN (...)query shape and apply type discrimination in Python, matching the existing filtered-search guard.entity:4:0andrelation:4:0both hydrating successfully.Test plan
uv run pytest tests/repository/test_vector_threshold.py tests/repository/test_vector_pagination.pyuv run ruff format src/basic_memory/repository/search_repository_base.py tests/repository/test_vector_threshold.py tests/repository/test_vector_pagination.pyuv run ruff check src/basic_memory/repository/search_repository_base.py tests/repository/test_vector_threshold.py tests/repository/test_vector_pagination.py